/*
 * @Author: 陈德基
 * @Date: 2021-11-15 18:58:22
 * @LastEditTime: 2021-11-15 18:58:52
 * @Description: 
 * @FilePath: \copy_gsy_github_app_flutter\lib\page\login\widgets\particle\particle_painter.dart
 * 联系方式：
 * wx: melody_2009
 * qq: 7815171323 
 */
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';

import 'particle_model.dart';

class ParticlePainter extends CustomPainter {
  List<ParticleModel> particles;

  ParticlePainter(this.particles);

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()..color = Colors.white.withAlpha(50);

    particles.forEach((particle) {
      final progress = particle.progress();
      final MultiTweenValues<ParticleOffsetProps> animation =
          particle.tween.transform(progress);
      final position = Offset(
        animation.get<double>(ParticleOffsetProps.x) * size.width,
        animation.get<double>(ParticleOffsetProps.y) * size.height,
      );
      canvas.drawCircle(position, size.width * 0.2 * particle.size, paint);
    });
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}
